package sealte.hvpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.UserDAO;
import sealte.hvpms.dao.impl.UserDAOImpl;

import com.google.gson.Gson;

public class UCVerifyName extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String un = (String)request.getParameter("username");
		if(un!=null&&!un.equals("")){
			un = URLDecoder.decode(un, "UTF-8");
			UserDAO ub = new UserDAOImpl();
			boolean flag = ub.verifyName(un);
			String message = "";
			if(flag){
				message = "该账号已被使用，请换用其他账号";
			}else{
				message = "您可以使用该账号";
			}
			Gson gson = new Gson();
			String json = gson.toJson(message);
			out.write(json);
		}else{
			out.println("谢绝跨路径访问！");
		}
	}

}
